<template>
    <div>
        <div class="form-section">
            <div class="form-item  form-item-style1">
                <div class="label-title">
                    <label>协议名称</label>
                </div>
                <div>
                    <p>{{detailData.AgreementName}}</p>
                </div>
            </div>
            <div class="form-item form-item-style1">
                <div class="label-title">
                    <label>项目名称</label>
                </div>
                <div>
                    <p>{{detailData.ProjectName}}</p>
                </div>
            </div>
            <div class="form-item form-item-style1">
                <div class="label-title">
                    <label>所属上级单位</label>
                </div>
                <div>
                    <p>{{detailData.ParentName}}</p>
                </div>
            </div>
            <div class="form-item form-item-style1">
                <div class="label-title">
                    <label>签订单位</label>
                </div>
                <div>
                    <p>{{detailData.SignUnit}}</p>
                </div>
            </div>
            <div class="form-item form-item-style1">
                <div class="label-title">
                    <label>签订日期</label>
                </div>
                <div>
                    <p>{{detailData.SignDate?detailData.SignDate.split(' ')[0]:''}}</p>
                </div>
            </div>
        </div>
        <div class="cut-off-rule"></div>
        <div class="form-section">
            <h3>附件信息</h3>
            <div class="form-item form-item-style1"
                 v-for="(item,index) in detailData.Files"
                 :key="index"
                 @click="preview(item.url)">
                <div class="label-title label-title1">
                    <label class="file-name">{{item.fileName}}</label>
                </div>
                <div class="right-section">
                    <span>预览</span>
                    <x-icon type="ios-arrow-right"
                            size="20"
                            class="icon-right"></x-icon>
                </div>
            </div>
        </div>
        <myMenu></myMenu>
    </div>
</template>
<script>
import myMenu from '@/commonComponents/menu'
export default {
    name: 'agreementDetail',
    data () {
        return {
            regImg: /\.(png|jpg|PNG|JPG|jpeg|JPEG|gif|GIF)$/,
            userInfo: {},
            detailData: {}
        }
    },
    components: {
        myMenu
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
        this.getDetail()
    },
    methods: {
        preview (filePath) {
            if (this.regImg.test(filePath)) {
                this.$router.push({
                    path: '/previewImg',
                    query: {
                        previewImg: filePath
                    }
                })
            } else {
                wx.miniProgram.navigateTo({
                    url: `/pages/openDocument/index?filePath=${filePath}`
                })
            }
        },
        getDetail () {
            let params = {
                'allowPaging': true,
                'business': 'getConstructionEleManProDetails',
                'data': {
                    'ID': this.$route.query.id
                },
                'pageIndex': 0,
                'pageSize': 0,
                'tokenId': '83480618EE9BD1A34FF4DC84E2FBDC14',
                'userId': this.userInfo.userid
            }
            this.$axiosAjax.getConfigJson(params).then((res) => {
                if (res.data.code === 0) {
                    this.detailData = res.data.data
                }
            }).catch(() => {

            }).finally(() => {
                this.$vux.loading.hide()
            })
        }
    }
}
</script>
<style scoped>
.sectionML20 {
    margin-left: 20px;
}
.file-name {
    width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
</style>
